package com.fpost.form.dto;

import com.fpost.domain.ArticleVersion;
import com.fpost.helper.Byline;
import com.fpost.manager.ArticleTypeManager;
import com.fpost.util.CommonUtils;
import com.fpost.util.DateUtil;


public class ArticleVersionDTO {
	
	private String versionId;
	private String articleId;
	private String articleTypeId;
	private String articleType;
	private String authorFirstName;
	private String authorLastName;
	private String authorUsername;
	private String title;
	private String summary;
	private String body;
	private String createdOn;
	private String createdIp;
	private String keywords;	
	private String hitCount;
	private String latestVersion;
	
	private Byline byline;
	
	public ArticleVersionDTO() {
		super();
	}
	
	public ArticleVersionDTO(ArticleVersion articleVersion) {

		this.versionId = String.valueOf(articleVersion.getArticleVersionId());
		this.articleId = String.valueOf(articleVersion.getArticle().getArticleId());
		this.articleTypeId = String.valueOf(articleVersion.getArticleTypeId());
		this.articleType = new ArticleTypeManager().get(articleVersion.getArticleTypeId()).getArticleType();

		this.authorFirstName = articleVersion.getArticle().getUser().getFirstName();
		this.authorLastName = articleVersion.getArticle().getUser().getLastName();
		this.authorUsername = articleVersion.getArticle().getUser().getUsername();
		
		this.title = articleVersion.getTitle();
		this.summary = CommonUtils.replaceNewline(articleVersion.getSummary());
		this.body = CommonUtils.replaceNewline(articleVersion.getBody());
		this.keywords = articleVersion.getKeywords();
		this.createdOn = DateUtil.dateToString(
				articleVersion.getCreatedOn(), DateUtil.COMPLEX_DATE_FORMAT_TIME_ZONE);
		this.createdIp = CommonUtils.privateIpAddress(articleVersion.getCreatedIp());
		this.hitCount = String.valueOf(articleVersion.getHitCount());
		this.latestVersion = (articleVersion.isLatestVersion() == true ? "Y" : "N");
	}
	
	public void setPropertiesForVersionLink(ArticleVersion articleVersion) {
		this.versionId = String.valueOf(articleVersion.getArticleVersionId());
		this.createdOn = DateUtil.dateToString(articleVersion.getCreatedOn(),
				DateUtil.COMPLEX_DATE_FORMAT_TIME_ZONE);		
	}
	
	public String getVersionId() {
		return versionId;
	}

	public void setVersionId(String versionId) {
		this.versionId = versionId;
	}

	public String getArticleType() {
		return articleType;
	}

	public void setArticleType(String articleType) {
		this.articleType = articleType;
	}

	public String getAuthorFirstName() {
		return authorFirstName;
	}

	public void setAuthorFirstName(String authorFirstName) {
		this.authorFirstName = authorFirstName;
	}

	public String getAuthorLastName() {
		return authorLastName;
	}

	public void setAuthorLastName(String authorLastName) {
		this.authorLastName = authorLastName;
	}

	public String getAuthorUsername() {
		return authorUsername;
	}

	public void setAuthorUsername(String authorUsername) {
		this.authorUsername = authorUsername;
	}

	public String getArticleId() {
		return articleId;
	}
	public void setArticleId(String articleId) {
		this.articleId = articleId;
	}
	public String getArticleTypeId() {
		return articleTypeId;
	}
	public void setArticleTypeId(String articleTypeId) {
		this.articleTypeId = articleTypeId;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}	
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public String getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(String createdOn) {
		this.createdOn = createdOn;
	}
	public String getCreatedIp() {
		return createdIp;
	}
	public void setCreatedIp(String createdIp) {
		this.createdIp = createdIp;
	}
	public String getKeywords() {
		return keywords;
	}
	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
	public String getHitCount() {
		return hitCount;
	}
	public void setHitCount(String hitCount) {
		this.hitCount = hitCount;
	}

	public String getLatestVersion() {
		return latestVersion;
	}

	public void setLatestVersion(String latestVersion) {
		this.latestVersion = latestVersion;
	}
	
	public Byline getByline() {
		return new Byline(this);
	}
}
